package com.ktwlsoft.fundmanage.utils;

import java.util.Random;

/**
 * 验证码工具
 *
 * @author Name on 2019/5/17 11:28
 * @version 1.0
 */
public class VerificationCodeUtil {

    /**设置字符*/
    /**private static final char[] CHARS="1234567890QWERTYUIOPASDFGHJKLZXCVBNM".toCharArray();*/
    private static final char[] CHARS="1234567890".toCharArray();

    /**设置随机数*/
    private static Random RANDOM = new Random();

    /**
      * 获取4位随机数 on 2019/5/17 11:29
      *
      * @return String
      */
    public static String getRandomString(){
        StringBuilder buffer = new StringBuilder();
        //获取随机chars下标
        int index;
        for(int i=0;i<4;i++){
            //获取随机chars下标
            index = RANDOM.nextInt(CHARS.length);
            buffer.append(CHARS[index]);
        }
        return buffer.toString();
    }

    /**
      * 检测是否是数字
      * 校验字符是否全是数字 on 2019/7/17 15:34
      *
      * @param s s
      * @return boolean
      */
    public static boolean isDigit(String s){
        for (int i = 0; i < s.length(); i++) {
            if (!Character.isDigit(s.charAt(i))) {
                return false;
            }
        }
        return true;
    }
}